<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="utf-8">
		<title>layui</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" th:href="@{/lib/layui-v2.5.5/css/layui.css}" media="all">
		<link rel="stylesheet" th:href="@{/css/public.css}" media="all">
	</head>
	<body>
		<div class="layuimini-container">
			<div class="layuimini-main">

				<fieldset class="table-search-fieldset">
					<legend>查询订单</legend>
					<div style="margin: 10px 10px 10px 10px">
						<form class="layui-form layui-form-pane" action="">
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">商品编号</label>
									<div class="layui-input-inline">
										<input type="hidden" name="merchantId" id="merchantId"  />
										<input type="text" name="shopId" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">商品名字</label>
									<div class="layui-input-inline">
										<input type="text" name="name" autocomplete="off" class="layui-input">
									</div>
								</div>
							</div>
								<div class="layui-inline">
									<button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i>
										索引
									</button>
								</div> 
							</div>
						</form>
					</div>
				</fieldset>

					<table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
					
					<script type="text/html" id="currentTableBar">
								<a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
								<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
					</script>
					



			</div>
		</div>
		<script th:src="@{/lib/layui-v2.5.5/layui.js}" charset="utf-8"></script>
		<script th:inline="none">
			layui.use(['form', 'table', 'laydate'], function() {
				var $ = layui.jquery,
					form = layui.form,
					table = layui.table,
					laydate = layui.laydate;
					
				var merchantId = "001";
				$("#merchantId").val(merchantId);

				laydate.render({
					elem: '#date',
					type: 'datetime',
					format: 'yyyy-MM-dd HH:mm:ss',
					max: 'new Date()'
				});
				
				var tableIns = null;

				// 监听搜索操作
				//多条件查询，带分页
				form.on('submit(data-search-btn)', function(data) {
					console.log("前端参数:" + JSON.stringify(data.field));
					var jsonstr = JSON.stringify(data.field);
					tableIns = table.render({
						elem: '#currentTableId',
						url: '/initCommodityByCondition',
						method: "post",
						contentType: 'application/json;charset=utf-8',
						where: {
							jsonstr: jsonstr
						},
						parseData: function(res) {
							return {
								"code": res.code,
								"msg": res.msg,
								"count": res.count,
								"data": res.data[0].list
							}
						},
						initSort: {
							field: 'repositoryId',
							type: 'desc'
						},
						toolbar: '#toolbarDemo',
						defaultToolbar: ['filter', 'exports', 'print', {
							title: '提示',
							layEvent: 'LAYTABLE_TIPS',
							icon: 'layui-icon-tips'
						}],
						cols: [
							[{
									type: "checkbox",
									width: 50
								},
								{
									field: 'shopId',
									width: 200,
									title: '商品编号',
									sort: true
								},
								{
									field: 'name',
									width: 200,
									title: '商品名字',
									sort: true
								},
								{
									field: 'price',
									width: 150,
									title: '商品价格',
									sort: true
								},
								{
									field: 'cost',
									width: 200,
									title: '商品成本',
									sort: true
								},
								{
									field: 'description',
									width: 200,
									title: '商品描述',
									sort: true
								},
								{
									field: 'manufacture',
									width: 200,
									title: '生产商',
									sort: true
								},
								{
									field: 'sales',
									width: 200,
									title: '销量',
									sort: true
								},
								{
									field: 'credential',
									width: 200,
									title: '商品凭证',
									sort: true
								},
								{
									title: '操作',
									minWidth: 150,
									toolbar: '#currentTableBar',
									align: "center"
								},


							]
						],
						limit: 10,
						limits: [10, 15, 20, 25, 50, 100],
						page: true,
						skin: 'row'

					});


					return false;
				});


				//删除单条商品记录
				table.on('tool(currentTableFilter)', function(obj) {
					var data = obj.data;
					var jsonstr = data.shopId;
					if (obj.event === 'delete') {
						layer.confirm('是否确定删除ID为：' + jsonstr + '的商品对象', function(index) {
							$.ajax({
								url: '/deleteOneCommodity',
								contentType: 'application/json;charset=utf-8',
								method: 'POST',
								data: jsonstr,
								success: function(res) {
									tableIns.reload();
									layer.alert(res.msg);
								}
							});
				
							layer.close(index);
						});
					}
				});
				
				
				//编辑单条商数据
				table.on('tool(currentTableFilter)', function(obj) {
					var data = obj.data;
					if (obj.event === 'edit') {
				
						var index = layer.open({
							title: '编辑商品数据',
							type: 2,
							shade: 0.2,
							maxmin: true,
							shadeClose: true,
							area: ['100%', '100%'],
							content: '/page/table/editCommodity.html',
							 success: function(layero, index){
							    var body = layer.getChildFrame('body', index);
							    var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
							    console.log(body.html()) //得到iframe页的body内容
							    body.find('#shopId').val(data.shopId);
								body.find('#name').val(data.name);
								body.find('#price').val(data.price);
								body.find('#cost').val(data.cost);
								body.find('#description').val(data.description);
								body.find('#manufacture').val(data.manufacture);
								body.find('#credential').val(data.credential);
								body.find('#sales').val(data.sales);
								//隐藏字段
								body.find('#typeId').val(data.typeId);
								body.find('#imgId').val(data.imgId);
								body.find('#merchantId').val(data.merchantId);
								body.find('#standard').val(data.standard);
							  }
						});
						$(window).on("resize", function() {
							layer.full(index);
						});
						return false;
					} 
				});
				
				
				



			});
		</script>

	</body>
</html>
